/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include <基本类型.h>
#include <vector>
#include <set>
#include <向量.h>
#include <string>
#include <__msvc_string_view.hpp>
#include <basic_vec.h>



std::vector<std::wstring> f_str_分割(const std::wstring& 源, const std::wstring& 分隔符);
std::vector<std::u16string> f_str_分割(const std::u16string& 源, const std::u16string& 分隔符);
std::vector<std::u16string> f_str_分割(const std::u16string& 源, const std::vector<std::u16string>& 分隔符);

void f_str_删除两头字符(std::wstring& 源, const std::wstring& 删除符);
void f_str_删除两头字符(std::wstring& 源, const std::wstring& 头, const std::wstring& 尾);

ivec2 f_str_查找到字符区间(std::wstring& 源, const std::wstring& 查找符, const std::wstring& 终止符);

std::u16string f_str_取到字符(std::u16string& 源, const std::u16string& 终止符);
wchar_t f_str_从跳过字符取字符(std::u16string& 源, const std::u16string& 跳过字符);


void f_str_去除空白字符(std::u16string& s);
bool f_str_去路径空白字符(std::u16string& path);

void f_str_数组填充末尾(const std::set<std::u16string>& key, std::u16string& s);



//std::vector<std::wstring_view> f_strView_分割(const std::wstring& str, wchar_t delimiter);


Inline std::vector<std::wstring_view> f_strView_分割(const std::wstring& str, wchar_t delimiter) {
	std::vector<std::wstring_view> result;
	std::wstring_view sv(str);
	size_t start = 0;
	for (size_t i = 0; i <= sv.size(); ++i) {
		if (i == sv.size() || sv[i] == delimiter) {
			result.emplace_back(sv.substr(start, i - start));
			start = i + 1;
		}
	}
	return result;
}


Inline std::vector<std::wstring_view> f_strView_parse_brackets(const std::wstring& input, wchar_t left_bracket, wchar_t right_bracket) {
	std::vector<std::wstring_view> result;
	int depth = 0;
	size_t start_index = 0;
	std::wstring_view sv(input);

	for (size_t i = 0; i < sv.size(); ++i) {
		if (sv[i] == left_bracket) {
			if (depth == 0) {
				start_index = i + 1;
			}
			depth++;
		} else if (sv[i] == right_bracket) {
			depth--;
			if (depth == 0) {
				result.emplace_back(sv.substr(start_index, i - start_index));
			}
		}
	}
	return result;
}


int32 f_str_find_词最后出现位置(const std::string& str, const std::string& word, bool 全字匹配 = false);


void f_str_去除指定词(std::string& str, const std::string& 词);


